package algorithm.heap;

import java.util.PriorityQueue;

/**
 * 小根堆排序
 *
 * @author csp 2021-12-04
 */
public class Code04_ArrayDistanceLessK {
    // 数组最大移动不超过k，给数组排序
    public void sortedArrDistanceLessK(int[] arr, int k) {

        PriorityQueue<Integer> heap = new PriorityQueue<>();
        int index = 0;

        for (; index <= Math.min(arr.length, k); index++) {
            heap.add(arr[index]);
        }

        int i = 0;
        for (; index < arr.length; i++, index++) {
            heap.add(arr[index]);
            arr[i] = heap.poll();
        }

        while (!heap.isEmpty()) {
            arr[i++] = heap.poll();
        }

    }



    public static void main(String[] args) {
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        queue.add(8);
        queue.add(4);
        queue.add(4);
        queue.add(9);
        queue.add(10);
        queue.add(3);
//        while (!queue.isEmpty()) {
//            System.out.println(queue.poll());
//        }
    }
}
